<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="org.edu.system.DBConnect" %>
<%@ page import="java.sql.*" %>
<%@page import="org.edu.system.LogWriter" %>
<%
	String tc_id = (String)(session.getAttribute("UserName"));
	String sql = "SELECT * FROM teacher WHERE tc_id = '" + tc_id + "'";
	System.out.println(sql);
	
	Connection con = DBConnect.getCon();
	Statement stmt = null;
	ResultSet rs = null;
	stmt = con.createStatement();
	rs = stmt.executeQuery(sql);//执行命令
	if (rs.next())// 如果记录集非空，表明有匹配的用户ID
	{
			//正常进行
	} else {
		// 否则登录失败
		// response.sendRedirect ( "MyJsp.jsp" );
		response.sendRedirect("login_failure.jsp");
	}
	String lesson_id = request.getParameter("lesson_id");
%>
<!DOCTYPE html>
<html>
<head>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta http-equiv="refresh" content="2" url="./tea_kaoqin.jsp?lesson_id=<%=lesson_id%>">
<meta charset="utf-8">
<title>教师教务管理系统 - 学生考勤</title>
</head>
<body style="width:900px; margin:0 auto;">
<%	
	//设置lesson的考勤状态为1
	sql = "update student set kaoqin='2' where course_list LIKE '%"+lesson_id+",%' and kaoqin != '2' and kaoqin != '1'";
	stmt = con.createStatement();
	stmt.executeUpdate(sql);//执行命令
	LogWriter.LogPrint("["+request.getRemoteAddr()+"] "+tc_id+" 开始考勤！");
	
%>
<table border="1" width="100%" style="text-align:center" class="table table-bordered">
	<tr height="1000px">
		<td width="20%" valign="top" style="padding-top:90px">
		<%
			sql = "select c.course_name,location,time from lesson l,course c where lesson_id ='"+lesson_id+"' and l.course_id = c.course_id";
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);//执行命令
			if(rs.next())
			{
				out.print("<h3>"+rs.getString("course_name")+"</h3>");
				out.print("<h3>"+rs.getString("location")+"</h3>");
				out.print("<h3>"+rs.getString("time")+"</h3>");
			}
		%>
			<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
			<input type="button" class="btn btn-danger btn-sm" value="结束考勤" onclick="javawwscript:location='<%=request.getContextPath()%>/SaveAttendance?lesson_id=<%=lesson_id%>'"/>
		</td>
		<td valign="top">
			<table border="1" width="100%" style="text-align:center" class="table table-striped table-bordered">
				<tr height="30px">
					<th style="text-align:center">学号</th>
					<th style="text-align:center">姓名</th>
					<th style="text-align:center">状态</th>
				</tr>
				<tr>
						<%
							sql = "SELECT stu_id,stu_name,kaoqin FROM student WHERE course_list LIKE \"%"+lesson_id+",%\"";
							
							stmt = null;
							rs = null;
							stmt = con.createStatement();
							rs = stmt.executeQuery(sql);//执行命令
							while(rs.next())
							{
								out.print("<tr>");
								out.print("<td>"+rs.getString("stu_id")+"</td>");
								out.print("<td>"+rs.getString("stu_name")+"</td>");
								if(rs.getString("kaoqin").equals("2"))
									out.print("<td>未签到</td>");
								else
									out.print("<td>已签到</td>");
								out.print("</tr>");
							}
						%>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>